package com.hmdp.config.bloomfilter;

import com.hmdp.service.IShopService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
//@Component
@RequiredArgsConstructor
public class BloomFilterWarmUp implements CommandLineRunner {

    private final IShopService shopService;
    private final RedisBloomFilter shopBloomFilter; // Redisson的布隆过滤器

    @Override
    public void run(String... args) {
        log.info("开始布隆过滤器预热...");
        long start = System.currentTimeMillis();

        List<Long> ids = shopService.queryAllShopIds();
        ids.stream().map(String::valueOf)
                .forEach(shopBloomFilter::add);

        log.info("布隆过滤器预热完毕. 共 {} 条店铺数据在 {}ms加载",
                ids.size(), System.currentTimeMillis() - start);
    }
}